$(document).ready(function(){
    let select_all = $('.desc >li > input[type="checkbox"]')
    let down_left = $('.down_left input[type="checkbox"]')
    // let all_checkbox = $('input[type="checkbox"]')
    let good = $('.buys')

    let select_good_title = good.find('li > input[type="checkbox"]')
    let select_good = good.find('.buy input[type="checkbox"]')

    // 全选
    // function click_all() {
    //     select_good_title.click()
    //     select_good.click()
    // }
    // (function(){
    //     select_all.click(function() {
    //         click_all()
    //         down_left.click()
    //     })
    // })();

    select_good_title.click(function(){
        let $this = $(this)
        let this_good = $this.parent().parent().parent().parent()
        let $select_good = this_good.find('.buy >input[type="checkbox"]')
        $select_good.click()
    })

    // 删除指定商品
    let delete_good = $('.down_left >li:nth-of-type(2) >a')
    delete_good.click(function() {
        let is_delete = confirm("请确定要删除选中商品")
        if(is_delete && select_good.is(':checked')){
            let $this = select_good.parent().find("input[type='checkbox']:checked")
            $this.parent().parent().remove()
        }else{
            alert("未选中删除的商品")
        }
    })
    // 清理购物车
    let delete_all = $(".down_left >li:last-child()")
    delete_all.click(function() {
        let is_delete = confirm("您确定要清楚购物车吗？")
        if(is_delete) {
            select_good.parent().parent().remove()
        }
    })

    let good_count = $(".good_count")
    let good_num = good_count.find("input[type='number']")
    let increase = good_count.find(".increase")
    let reduce = good_count.find(".reduce")
    // console.log(reduce)
    function check_reduce_disabled(num) {
        let input_number_val = parseInt(num.val())
        // console.log(input_number_val)
        if(input_number_val > 1) {
            reduce.removeClass('disabled')
        } else {
            reduce.addClass('disabled')
        }
    }
    increase.click(function() {
        let input_number = $(this).parent().find('input')
        let input_number_val = parseInt(input_number.val())
        let count =input_number.val(input_number_val + 1)
        check_reduce_disabled(count)
    })
    reduce.click(function() {
        let input_number = $(this).parent().find('input')
        let input_number_val = parseInt(input_number.val())
        if(input_number_val >0) {
            let count = input_number.val(input_number_val - 1)
            check_reduce_disabled(count)
        }

    })
    good_num.blur(function() {
        let count = good_num
        check_reduce_disabled(count)
    })

    let pay = $('.pay')
    pay.click(function() {
        console.log(pay)
        window.location.href = '/order.html'
    })
})